package com.zhuiyun.educations.api.video.service.impl;

import com.zhuiyun.educations.api.newCourse.entity.DTO.CourseDTO;
import com.zhuiyun.educations.api.video.entity.Comment;
import com.zhuiyun.educations.api.video.entity.CommentDTO;
import com.zhuiyun.educations.api.video.mapper.CommentMapper;
import com.zhuiyun.educations.api.video.service.CommentService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import com.zhuiyun.educations.util.pageUtil.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName CommentServiceImpl
 * @Description TODO
 * @Author 杨友朋
 * @Date 2023/7/12 11:04
 **/
@Service
public class CommentServiceImpl implements CommentService {
    @Resource
    CommentMapper commentMapper;

    /**
    * @Author 杨友朋
    * @Description TODO 分页全查评论
    * @Date 2023/7/12 11:05
    * @Return
    * @param commentDTO,pageRequest
     */
    @Override
    public PageResult selectComment(CommentDTO commentDTO, PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        //查询
        List<CommentDTO> list = commentMapper.selectComment(commentDTO);
        return MybatisPageHelper.getPageResult(list);
    }


    @Override
    public Integer delById(Integer id) {

        return commentMapper.delById(id);
    }

    @Override
    public CommonResult insertComment(Comment comment) {
        Date date=new Date();
        comment.setCreateTime(date);
        comment.setUpdateTime(date);
        commentMapper.insertSelective(comment);
        return CommonResult.ok("评论成功");
    }
}
